<?php
/**
 * WB_PersistentObjClass
 * 
 * @author Jean-Lou Dupont
 * @version @@package-version@@
 * @id $Id: PersistentObjClass.php 110 2008-03-09 03:27:05Z jldupont $
 */

 //{{include
 require_once 'web-bloks/CacheableObjectClass/CacheableObjectClass.php';
#require_once 'web-bloks/ObjFactory/ObjFactory.php';
#require_once 'web-bloks/Identifier/Identifier.php';
 //include}}
 
 class WB_PersistentObjClass
 	extends WB_CacheableObjectClass
 {
	/**
	 * Unique ID of the object.
	 * Useful at object creation time
	 * Must be stored along with the object
	 * when the creation phase is in progress.
	 * Used by WB_ObjStore derived classes.
	 * 
	 * @private
	 */ 	
	var $creation_uid = null;
	
 	/**
 	 * WB_Identifier
 	 * @private
 	 */
 	var $identifier = null;
	
 	/**
 	 * Expiration Status 
 	 * NOTE: no need to store this field,
 	 *       hence the underscore.
 	 * 
 	 * @private
 	 */
	var $_expired = null;
	
 	/**
 	 * Constructor
 	 */
	public function __construct( $id, $params = null )
	{
		// $id is either:
		// 1- a string used to construct a default WB_Identifier
		// 2- a WB_Identifier
		if ( is_string( $id ) )
		{
			$this->identifier = WB_ObjFactory::factory( 'WB_Identifier', $params );
			$this->identifier->set( $id );
		}	
		
		if ( $id instanceof WB_Identifier )
			$this->identifier = $id;
			
		parent::__construct( $params );
	}
		
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// Interface
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%				
	/**
	 * Returns the expiration status
	 * 
	 * @return boolean
	 */
	public function isExpired()
	{
		// if the status is already computed...
		if ( !is_null( $this->_expired ))
			return $this->_expired;
		
		// else, we need to figure out at this instant
		// Query the parent class for the relevant information
		$expiration_datetime = $this->getExpire();
		$now = date( 'Y-m-d H:i:s' );
		
		$expiration_time = strtotime( $expiration_datetime );
		$now_time = strtotime( $now );
		
		return ( $expiration_time > $now );
	}

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// 
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%				

 } // end class declaration